home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / File / File Info < prev    next >
Encoding:
Text File  |  1999-03-04  |  3.3 KB  |  141 lines  |  [TEXT/ToyS]

  1. -- Preferences
  2. property kasPrefName : "File Info"
  3. property kasFontName : "Monaco"
  4. property kasFontSize : 9
  5. property kasTickerInit : 8
  6.  
  7. -- Globals
  8. global gasInfoWind -- Info window
  9. global gasInfoPos -- Position of info window
  10. global gasTicker -- How many idles until quit
  11. global gasRunning -- Running?
  12.  
  13.  
  14. on open fsObjs
  15.     try
  16.         set gasRunning to gasRunning + 1
  17.     on error
  18.         set gasRunning to 1
  19.         
  20.         pfLoad()
  21.         
  22.         set gasInfoWind to display info titled kasPrefName ¬
  23.             located at gasInfoPos
  24.     end try
  25.     
  26.     set gasTicker to kasTickerInit
  27.     
  28.     repeat with fsObj in fsObjs
  29.         ShowInfo(fsObj)
  30.         pause for 3 with seconds timing
  31.     end repeat
  32. end open
  33.  
  34.  
  35. on quit
  36.     -- Save Screen Location of info window if changed
  37.     try
  38.         set infoPos to screen location of ¬
  39.             (display info gasInfoWind with disposal)
  40.         if (infoPos is not gasInfoPos) then
  41.             set gasInfoPos to infoPos
  42.             pfSave()
  43.         end if
  44.         set gasRunning to "X"
  45.     on error
  46.         beep
  47.     end try
  48.     continue quit
  49. end quit
  50.  
  51.  
  52. on idle
  53.     set gasTicker to gasTicker - 1
  54.     if (gasTicker is 0) then quit
  55.     return 15
  56. end idle
  57.  
  58.  
  59. on ShowInfo(fsObj)
  60.     set xInfo to extended info for fsObj
  61.     set aInfo to alias info from fsObj
  62.     
  63.     set lineNo to 1
  64.     
  65.     if (catalog kind of xInfo is a folder) then
  66.         set fKind to "Folder"
  67.     else if (catalog kind of xInfo is an alias) then
  68.         set fKind to "Alias"
  69.     else if (catalog kind of xInfo is a file) then
  70.         set fKind to "File"
  71.     else
  72.         set fKind to "Unknown"
  73.     end if
  74.     
  75.     set lineNo to ShowLine("Name", catalog name of xInfo, lineNo)
  76.     set lineNo to ShowLine("Kind", fKind, lineNo)
  77.     set lineNo to ShowLine("Type", system type of xInfo, lineNo)
  78.     set lineNo to ShowLine("Creator", system creator of xInfo, lineNo)
  79.     set lineNo to ShowLine("Created", (catalog creation date of xInfo) as string, lineNo)
  80.     set lineNo to ShowLine("Modified", (catalog modification date of xInfo) as string, lineNo)
  81.     -- set lineNo to ShowLine("Backed up", (catalog archival date of xInfo) as string, lineNo)
  82.     
  83.     if (fKind is "Folder") then
  84.         set lineNo to ShowLine("Items", number of items within of xInfo, lineNo)
  85.         set lineNo to ShowLine("View", finder view setting of xInfo, lineNo)
  86.     else
  87.         set lineNo to ShowLine("Data Len", GigaStr(data fork length of xInfo), lineNo)
  88.         set lineNo to ShowLine("Rsrc Len", GigaStr(resource fork length of xInfo), lineNo)
  89.     end if
  90. end ShowInfo
  91.  
  92.  
  93. on ShowLine(label, parm, lineNo)
  94.     display info gasInfoWind ¬
  95.         message (PadStr(label & ":", 10, false) & parm) ¬
  96.         at line lineNo ¬
  97.         using font kasFontName ¬
  98.         using size kasFontSize
  99.     
  100.     return lineNo + 1
  101. end ShowLine
  102.  
  103.  
  104. on GigaStr(n)
  105.     if (n > 1024 * 1024 * 1024 * 2) then -- > 2 GB?
  106.         set freeK to "" & ((0.0 + (round (n / (1024 * 1024 * 102.4)))) / 10) & " GB"
  107.     else if (n > 1024 * 1024 * 2) then -- > 2 MB?
  108.         set freeK to "" & ((0.0 + (round (n / (1024 * 102.4)))) / 10) & " MB"
  109.     else if (n > 1024 * 2) then -- > 2 MB?
  110.         set freeK to "" & ((0.0 + (round (n / (102.4)))) / 10) & " KB"
  111.     else
  112.         set freeK to "" & n & "  B"
  113.     end if
  114. end GigaStr
  115.  
  116.  
  117. on PadStr(str, len, atLeft)
  118.     set pad to "                                        "
  119.     
  120.     if atLeft then
  121.         return the text from character -1 to -len of (pad & str)
  122.     else
  123.         return the text from character 1 to len of (str & pad)
  124.     end if
  125. end PadStr
  126.  
  127.  
  128. on pfLoad()
  129.     try
  130.         set ourPrefs to (load preference named kasPrefName)
  131.         set gasInfoPos to item 1 of ourPrefs
  132.     on error
  133.         set gasInfoPos to {-1, -1}
  134.     end try
  135. end pfLoad
  136.  
  137.  
  138. on pfSave()
  139.     save preference {gasInfoPos} named kasPrefName
  140. end pfSave
  141.